public class CalculateTest {
    public int calculate(char[] inputs) {
        String inputString = new String(inputs);
        while (inputString.contains("*")) {
            int i = inputString.indexOf("*");
            String substring = inputString.substring(i - 1, i + 2);
            int a = Integer.parseInt(substring.split("\\*")[0]);
            int b = Integer.parseInt(substring.split("\\*")[1]);
            Integer result = a * b;
            inputString = inputString.replace(substring, result.toString());
        }
        while (inputString.contains("/")) {
            int i = inputString.indexOf("/");
            String substring = inputString.substring(i - 1, i + 2);
            int a = Integer.parseInt(substring.split("\\/")[0]);
            int b = Integer.parseInt(substring.split("\\/")[1]);
            Integer result = a / b;
            inputString = inputString.replace(substring, result.toString());
        }
        while (inputString.contains("+")) {
            int i = inputString.indexOf("+");
            String substring = inputString.substring(i - 1, i + 2);
            int a = Integer.parseInt(substring.split("\\+")[0]);
            int b = Integer.parseInt(substring.split("\\+")[1]);
            Integer result = a + b;
            inputString = inputString.replace(substring, result.toString());
        }
        while (inputString.contains("-")) {
            int i = inputString.indexOf("-");
            if (i == 0) break;
            String substring = inputString.substring(i - 1, i + 2);
            int a = Integer.parseInt(substring.split("-")[0]);
            int b = Integer.parseInt(substring.split("-")[1]);
            Integer result = a - b;
            inputString = inputString.replace(substring, result.toString());
        }
        return Integer.parseInt(inputString);
    }

    public static void main(String[] args) {
        char[] inputs = {'1', '-', '4', '/', '2'};
        CalculateTest test = new CalculateTest();
        int result = test.calculate(inputs);
        System.out.println("Result: " + result);
    }
}
